package com.neusoft.common.db;

import org.springframework.jdbc.core.*;

import java.sql.*;

/**
 * 分页参数设置类
 * Created By YZ at Jun 30, 2010 11:27:14 AM
 * Class:EncodingPreparedStatementSetter
 *
 */
public class EncodingPreparedStatementSetter implements
        PreparedStatementSetter, ParameterDisposer{
    private final Object[] args;

    public EncodingPreparedStatementSetter(Object[] args){
        this.args = args;
    }

    public void setValues(PreparedStatement ps) throws SQLException{
        if(this.args != null){
            for(int i = 0; i < this.args.length; i++){
                Object arg = this.args[i];

//				if (String.class.isInstance(arg)) {
//					arg = EncodingConvert.convertToGBK(arg.toString());
//				}

                if(arg instanceof SqlParameterValue){
                    SqlParameterValue paramValue = (SqlParameterValue) arg;
                    StatementCreatorUtils.setParameterValue(ps, i + 1,
                                                            paramValue, paramValue.getValue());
                } else{
                    StatementCreatorUtils.setParameterValue(ps, i + 1,
                                                            SqlTypeValue.TYPE_UNKNOWN, arg);
                }
            }
        }
    }

    public void cleanupParameters(){
        StatementCreatorUtils.cleanupParameters(this.args);
    }


}
